package org.zhouhe.modules.upload;

import java.io.File;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;
import org.zhouhe.base.BaseAction;

public class UploadifyAction extends BaseAction {
	private static final long serialVersionUID = 1653060788696496243L;
	private File[] files;
	private String[] filesFileName;
	private String dir;
	public void uploadify() {
		try {
			String[] filePathInfo = UploadUtils.getImagePathInfo(dir, filesFileName[0]);
			UploadUtils.writeFile(this.files[0], filePathInfo[1]);
			HttpServletResponse response = ServletActionContext.getResponse();
			PrintWriter out = response.getWriter();
			out.print(filePathInfo[2]);
			out.flush();
			out.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void setFiles(File[] files) {
		this.files = files;
	}

	public File[] getFiles() {
		return files;
	}

	public void setFilesFileName(String[] filesFileName) {
		this.filesFileName = filesFileName;
	}

	public String[] getFilesFileName() {
		return filesFileName;
	}

	public void setDir(String dir) {
		this.dir = dir;
	}

	public String getDir() {
		return dir;
	}
}
